package emstest;

import com.lwx.smipleemps.common.domain.Admin;
import com.lwx.smipleemps.common.utils.HibernateUtils;
import com.lwx.smipleemps.dao.AdminDao;
import com.lwx.smipleemps.dao.AdminDaoImpl;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.junit.Test;

public class DaoTest {
    @Test
    public void test1(){
       //获取Session
        /* Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
        ServiceRegistry serviceRegistry =new  ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        Session session = sessionFactory.openSession();
        Admin admin = (Admin) session.get(Admin.class, 1);
        System.out.println(admin);*/
     /*   Session session = HibernateUtils.getSession();
        System.out.println(session.hashCode());
        System.out.println(HibernateUtils.getSession().hashCode());
        System.out.println(HibernateUtils.getSession().hashCode());
        System.out.println(HibernateUtils.getSession().hashCode());
        System.out.println(HibernateUtils.getSession().hashCode());*/
    }

    @Test
    public void test2(){
        Admin admin11 = new Admin().setName("test1").setPassword("test11");
        Session session = HibernateUtils.getSession();
        HibernateUtils.beginSessionTransaction();
        session.save(admin11);
        HibernateUtils.commitAndcloseSession();
    }


    @Test
    public void test3(){
        AdminDao adminDao = new AdminDaoImpl();
        Admin admin = adminDao.selectAdminByName("test");
        System.out.println(admin);
    }
}
